home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Gurus! Is it correct?
- Date: Mon, 05 Feb 1996 00:33:01 GMT
- Organization: Netcom
- Message-ID: <31154f3e.254843520@nntp.ix.netcom.com>
- References: <4eqvtg$cg5@israel-info.datasrv.co.il> <4etnju$6gn@rolaids.frco.com> <4f0n8s$a3b@news2.ios.com> <311403bf.169980736@nntp.ix.netcom.com> <4f2koo$q5a@news2.ios.com>
- NNTP-Posting-Host: ix-dc9-06.ix.netcom.com
- X-NETCOM-Date: Sun Feb 04 4:32:21 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- vlad@gramercy.ios.com (Vlastimil Adamovsky) wrote:
-
- > miker3@ix.netcom.com (Mike Rubenstein) wrote:
- >
- > >vlad@gramercy.ios.com (Vlastimil Adamovsky) wrote:
- > >> I don't think the virtual destructor is necessary in this specific
- > >> case where you have no added data in subclasses.
- >
- > >Why do you think having data has anything to do with it? From draft
- > >5.3.5:
- >
- > > In the first alternative (delete object), if the static type
- > > of the operand is different from its dynamic type, the static
- > > type shall be a base class of the operand's dynamic type
- > > and the static type shall have a virtual destructor or the
- > > behavior is undefined.
- >
- >
- > I prefer slightly more simple explanation as follows:
- > (The Design and Evolution of C++, chapter 10.5 page 216)
- > ....
- > Had a virtual destructor not been used, the cleanup specified in
- > Y's (in our case class B) destructor would not have been performed.
- >
- >
- > Here you see you have choice to use virtual destructor or not.
-
- But you don't have a choice.
-
- Or rather, you have a choice of writing a correct program or one that
- might do anything since it invokes undefined behavior.
-
- Your quote from D&E explains the reasoning and, no doubt, is correct
- on many if not most compilers, but the draft has changed the rules a
- bit. In particular, it is not guaranteed that the cleanup in B's
- destructor will not be performed. Nor is it guaranteed that any
- destructor will be called. Nothing is guaranteed, since the behavior
- is undefined.
-
-
- Michael M Rubenstein
-